package com.breeze.blockchain.controller.admin.form.role;

import static com.breeze.blockchain.mybatis.entity.table.RolePermissionTable.ROLE_PERMISSION;

import com.breeze.blockchain.mybatis.entity.RolePermissionDo;
import com.breeze.components.mybatis.page.AbstractPageQuery;
import com.mybatisflex.core.query.If;
import com.mybatisflex.core.query.QueryWrapper;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 权限列表
 *
 * @author breeze
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Schema
public class RolePermissionPageForm extends AbstractPageQuery<RolePermissionDo> {

  @Schema(title = "角色权限ids")
  List<Long> ids;

  @Schema(title = "角色id")
  Long roleId;

  @Override
  public QueryWrapper toQueryWrapper() {
    return super.toQueryWrapper()
        .where(
            ROLE_PERMISSION
                .ROLE_ID
                .eq(getRoleId(), If::notNull)
                .and(ROLE_PERMISSION.ID.in(getIds(), If::isNotEmpty)))
        .orderBy(ROLE_PERMISSION.ID.desc());
  }
}
